/*
 * @Author: maomao
 * @Date: 2021-03-29 10:09:52
 * @Description: 配置公共弹窗
 * @FilePath: \dictionary-web\src\utils\dialog-util.ts
 */
import { custom } from "devextreme/ui/dialog";
import Vue from "vue";

export interface ConfirmOption {
    /** 标题 */
    title?: string | undefined;
    /** 内容 */
    content?: string | undefined;
    /** 确认名称 */
    confirm?: string | undefined;
    /** 取消名称 */
    cancel?: string | undefined;
    /** 是否需要标题 */
    showTitle?: boolean | undefined;
}

export class DialogUtil  {
    
    /**
     * 
     * @param options 
     * title 标题 content 内容 confirm 确定按钮名称 showTitle 是否需要标题 默认[false]
     * @returns 确认按钮 true 确认 false 取消
     */
    static async confirm(options: ConfirmOption):Promise<boolean> {
        
        let myDialog = custom({
            title: options.title ?? '温馨提示',
            showTitle: options.showTitle??false,
            messageHtml: options.content ?? "<b>确认关闭吗</b>",
            buttons: [
                
                {
                    text: options.confirm?? "确认",
                    onClick: (e) => {
                        return { buttonText: true }
                    },
                },
                {
                    text: options.cancel?? "取消",
                    onClick: (e) => {
                        return { buttonText: false }
                    }
                },

            ],
        });
        let dialogResult = await myDialog.show();
        return dialogResult.buttonText;
    }
}